package org.jash.utils.net

import com.tencent.mmkv.MMKV
import okhttp3.JavaNetCookieJar
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import org.jash.converters.HtmlConverterFactory
import retrofit2.Retrofit
import retrofit2.converter.scalars.ScalarsConverterFactory
import java.net.CookieManager
import java.net.CookiePolicy
//var base_url:String = "https://www.ting13.cc"
var base_url:String = "https://www.ysts.cc"
private val client by lazy {
    OkHttpClient.Builder()
        .cookieJar(JavaNetCookieJar(CookieManager(MMKV.getRootDir()?.let { MMKVCookieStore() }, CookiePolicy.ACCEPT_ALL)))
        .addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
        .build()
}
val retrofit by lazy {
    Retrofit.Builder()
        .baseUrl(base_url)
        .client(client)
        .addCallAdapterFactory(SynchronousCallAdapterFactory())
        .addConverterFactory(BitmapConvertFactory.create())
        .addConverterFactory(ScalarsConverterFactory.create())
        .addConverterFactory(HtmlConverterFactory.create())
        .build()
}

inline fun <reified T> service(): T = retrofit.create(T::class.java)